import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:share_fit/app/controllers/base/base_sports_controller.dart';
import 'package:share_fit/app/routes/sports_routes.dart';
import 'package:share_fit/app/ute/uteped_const.dart';

import 'state.dart';

class MovementLogic extends BaseSportsController {
  final MovementState state = MovementState();

  GoogleMapController? googleMapController;

  void selectSport(int index) {
    state.index = index;
    update(['sprot_select']);
  }

  void selectSportTarget(int index) {
    state.targetIndex = index;
    update(['sprot_select_target']);
  }

  void timerDown(var count) {
    state.timerCount = count;
    update(['timer_down']);
  }

  @override
  String getRemotePath() {
    return UTEPedConst.pathSports;
  }

  @override
  void initState() {
  }

  @override
  void onRemoteEvent(event, method) {
    // TODO: implement onRemoteEvent
  }

  @override
  void onClose() {
    super.onClose();
    googleMapController?.dispose();
  }

  void goMotionPage() {
    Get.offNamed(SportsRoutes.motionPage, arguments: {'goal': 0, 'duration': 0, 'calories': 0});
  }

  goGoalSettingPage() {
    Get.toNamed(SportsRoutes.goalSettingPage, arguments: state.movementTopSports[state.index].type.code);
  }

  goCountDownPage() {
    uTEPedSports.start(workoutType: state.movementTopSports[state.index].type.code);
  }

  onMapCreated(GoogleMapController controller) {
    googleMapController = controller;
    // 重新获取当前定位
    uTEPedSports.getCurrentLocation().then((pos) {
      controller.moveCamera(CameraUpdate.newLatLng(LatLng(pos.latitude, pos.longitude)));
    });
  }
}
